﻿using System;
using UMC.Data;
using UMC.Net;

namespace UMC.Bridge
{
    public class BridgeConfig : Record
    {
        public StringValue Domain
        {
            get; set;
        }
        public int? Key
        {
            get; set;
        }
        public string Caption
        {
            get; set;
        }
        public int? BridgeKey
        {
            get; set;
        }
        public long? AllowSize
        {
            get; set;
        }

        public StringValue Time { get; set; }// = StringValue.Empty;
        public StringValue Cache
        {
            get; set;
        }




        readonly static Action<BridgeConfig, object>[] _SetValues = new Action<BridgeConfig, object>[] { (r, t) => r.AllowSize = Reflection.ParseObject(t, r.AllowSize), (r, t) => r.BridgeKey = Reflection.ParseObject(t, r.BridgeKey), (r, t) => r.Cache = Reflection.ParseObject(t, r.Cache), (r, t) => r.Caption = Reflection.ParseObject(t, r.Caption), (r, t) => r.Domain = Reflection.ParseObject(t, r.Domain), (r, t) => r.Key = Reflection.ParseObject(t, r.Key), (r, t) => r.Time = Reflection.ParseObject(t, r.Time) };
        readonly static string[] _Columns = new string[] { "AllowSize", "BridgeKey", "Cache", "Caption", "Domain", "Key", "Time" };
        protected override void SetValue(string name, object obv)
        {
            var index = Utility.Search(_Columns, name, StringComparer.CurrentCultureIgnoreCase);
            if (index > -1) _SetValues[index](this, obv);
        }
        protected override void GetValues(Action<String, object> action)
        {
            AppendValue(action, "AllowSize", this.AllowSize);
            AppendValue(action, "BridgeKey", this.BridgeKey);
            AppendValue(action, "Cache", this.Cache);
            AppendValue(action, "Caption", this.Caption);
            AppendValue(action, "Domain", this.Domain);
            AppendValue(action, "Key", this.Key);
            AppendValue(action, "Time", this.Time);
        }

        protected override RecordColumn[] GetColumns()
        {
            var cols = new RecordColumn[7];
            cols[0] = RecordColumn.Column("AllowSize", this.AllowSize);
            cols[1] = RecordColumn.Column("BridgeKey", this.BridgeKey);
            cols[2] = RecordColumn.Column("Cache", this.Cache);
            cols[3] = RecordColumn.Column("Caption", this.Caption);
            cols[4] = RecordColumn.Column("Domain", this.Domain);
            cols[5] = RecordColumn.Column("Key", this.Key);
            cols[6] = RecordColumn.Column("Time", this.Time);
            return cols;
        }


    }

}
